/**
 * @file xgame_2048.h
 *
 */

#ifndef XGAME_2048
#define XGAME_2048

#ifdef __cplusplus
extern "C" {
#endif

/*********************
 *      INCLUDES
 *********************/
#include <stdint.h>

/*********************
 *      DEFINES
 *********************/

/**********************
 *      TYPEDEFS
 **********************/
  /*game config*/
struct _xgame_2048cfg{
  uint8_t col_count;
  uint8_t row_count;
  uint16_t win_max;
};

struct _xgame_2048{
  /*game config*/
  const struct _xgame_2048cfg *cfg;
  /*game data*/
  uint16_t random_vol;
  uint16_t *matrix;
  /*game buf*/
  uint16_t *row_buf;
};

/**********************
 * GLOBAL PROTOTYPES
 **********************/

/**
 * game initialization
 * @param game      uninitialized game structure
 * @param cfg       config of 2048 games
 * @param matrix    matrix of 2048 games, the size must be greater than (row_count * col_count)
 * @param row_buf   row buffer of 2048 games, the size must be greater than row_count
 * @return          void
 */
void xgame_2048_init(struct _xgame_2048 *game, const struct _xgame_2048cfg *cfg,
                     uint16_t *matrix, uint16_t *row_buf);

/*key , return */
/**
 * Game button processing
 * @param game      initialized game structure
 * @param key       0left, 1right, 2top, 3down
 * @return          0contiue, -1fail, 1win
 */
int8_t xgame_2048_key_pro(struct _xgame_2048 *game, uint8_t key);

/**********************
 *      MACROS
 **********************/


#ifdef __cplusplus
} /*extern "C"*/
#endif

#endif /*XGAME_2048*/
